import { create } from 'zustand'
const url = 'http://geek.itheima.net/v1_0/channels'

export const userStore = create((set) => ({
  user: 'admin',
  loginCount: 0,
  channelList: [],
  setUser: (user) => set(() => ({ user })),
  setLoginCount: (addCount) => set((state) => ({ loginCount: state.loginCount + addCount })),
  getChannelList: async () => {
    const res = await fetch(url)
    const data = await res.json()
    set(() => ({ channelList: data.data.channels }))
  },
}))
